<template>
  <div>
    <el-tree
      ref="tree"
      node-key="id"
      show-checkbox
      default-expand-all
      check-strictly=""
      :data="list"
      :props="{label:'name'}"
    />
    <el-row type="flex" justify="end">
      <el-button type="primary" size="mini" @click="hSubmit">确认</el-button>
      <el-button type="primary" size="mini">取消</el-button>
    </el-row>
  </div>
</template>

<script>
import { transDataToTreeData } from '@/utils'
import { getPermissionList } from '@/api/permissions'
import { getDetailRoles, assignPrem } from '@/api/settings'

export default {
  name: 'VueHrAssignPermission',
  props: {
    curId: {
      type: String,
      required: true
    }

  },

  data() {
    return {
      list: []

    }
  },
  created() {
    this.loadPermissionList()
  },
  methods: {
    async hSubmit() {
      const permIds = this.$refs.tree.getCheckedKeys()
      await assignPrem({ id: this.curId, permIds: permIds })
      this.$emit('success')
    },
    async loadPermissionList() {
      const detail = await getDetailRoles(this.curId)
      this.$refs.tree.setCheckedKeys(detail.data.permIds)
      const res = await getPermissionList()
      this.list = transDataToTreeData(res.data)
    }

  }
}
</script>

<style lang="scss" scoped>

</style>
